package org.oslims.client.view.impl;

import org.oslims.client.view.RootView;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.StackLayoutPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class RootViewImpl extends BaseViewImpl implements RootView {

	public static interface Resources extends ClientBundle {

		ImageResource logo();
	}

	private static final Resources RESOURCES = GWT.create(Resources.class);
	Image logo = new Image(RESOURCES.logo());

	StackLayoutPanel menuPanel = new StackLayoutPanel(Unit.EM);
	private Button userManagementLink = new Button("User Management");
	private Button departmentManagementLink = new Button("Department Management");
	private Button parameterManagementLink = new Button("Parameter Management");
	private Button analysisManagementLink = new Button("Analysis Management");
	private Button sampleTypeManagementLink = new Button("Sample Type Management");
	private Button requestManagementLink = new Button("Request Management");
	private Button sampleManagementLink = new Button("Sample Management");
	private Button analysisPlaningLink = new Button("Planing");
	private Button enterResultsLink = new Button("Enter Values");
	private Button labValidateResultsLink = new Button("Lab Validation");
	private Button scientValidateResultsLink = new Button("Scientifical Validation");
	private Button showResultsLink = new Button("View Results");

	private DockLayoutPanel appPanel = new DockLayoutPanel(Unit.EM);

	public RootViewImpl() {

		appPanel.addNorth(logo, 5);

		VerticalPanel requestWrapper = new VerticalPanel();
		VerticalPanel requests = new VerticalPanel();
		requests.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		requests.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		requestManagementLink.setWidth("14em");
		requests.add(requestManagementLink);
		requestWrapper.add(requests);
		menuPanel.add(requestWrapper, "Requests", 3);

		VerticalPanel samplesWrapper = new VerticalPanel();
		VerticalPanel samples = new VerticalPanel();
		samples.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		samples.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		sampleManagementLink.setWidth("14em");
		samples.add(sampleManagementLink);
		samplesWrapper.add(samples);
		menuPanel.add(samplesWrapper, "Samples", 3);

		VerticalPanel analysisWrapper = new VerticalPanel();
		VerticalPanel analysis = new VerticalPanel();
		analysis.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		analysis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		analysisPlaningLink.setWidth("14em");
		analysis.add(analysisPlaningLink);
		analysisWrapper.add(analysis);
		menuPanel.add(analysisWrapper, "Analysis", 3);

		VerticalPanel enterResultsWrapper = new VerticalPanel();
		VerticalPanel enterResults = new VerticalPanel();
		enterResults.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		enterResults.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		enterResultsLink.setWidth("14em");
		enterResults.add(enterResultsLink);
		enterResultsWrapper.add(enterResults);

		labValidateResultsLink.setWidth("14em");
		enterResults.add(labValidateResultsLink);

		scientValidateResultsLink.setWidth("14em");
		enterResults.add(scientValidateResultsLink);

		showResultsLink.setWidth("14em");
		enterResults.add(showResultsLink);

		menuPanel.add(enterResultsWrapper, "Results", 3);

		VerticalPanel configurationWrapper = new VerticalPanel();
		VerticalPanel configuration = new VerticalPanel();

		configuration.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		configuration.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		userManagementLink.setWidth("14em");
		configuration.add(userManagementLink);
		configuration.setCellVerticalAlignment(userManagementLink, HasVerticalAlignment.ALIGN_TOP);

		departmentManagementLink.setWidth("14em");
		configuration.add(departmentManagementLink);
		configuration.setCellVerticalAlignment(departmentManagementLink, HasVerticalAlignment.ALIGN_TOP);

		parameterManagementLink.setWidth("14em");
		configuration.add(parameterManagementLink);

		analysisManagementLink.setWidth("14em");
		configuration.add(analysisManagementLink);

		sampleTypeManagementLink.setWidth("14em");
		configuration.add(sampleTypeManagementLink);

		configurationWrapper.add(configuration);
		menuPanel.add(configurationWrapper, "Configuration", 3);

		menuPanel.showWidget(0);

		appPanel.addWest(menuPanel, 15);

		initWidget(appPanel);
	}

	@Override
	public DockLayoutPanel getMainWidget() {
		return appPanel;
	}

	@Override
	public HasClickHandlers getDepartmentManagementLink() {
		return departmentManagementLink;
	}

	@Override
	public HasClickHandlers getUserManagementLink() {
		return userManagementLink;
	}

	@Override
	public HasClickHandlers getParameterManagementLink() {
		return parameterManagementLink;
	}

	@Override
	public HasClickHandlers getAnalysisManagementLink() {
		return analysisManagementLink;
	}

	@Override
	public HasClickHandlers getSampleTypeManagementLink() {
		return sampleTypeManagementLink;
	}

	@Override
	public HasClickHandlers getRequestManagementLink() {
		return requestManagementLink;
	}

	@Override
	public HasClickHandlers getSampleManagementLink() {
		return sampleManagementLink;
	}

	@Override
	public Button getAnalysisPlaningLink() {
		return analysisPlaningLink;
	}

	@Override
	public HasClickHandlers getEnterResultsLink() {
		return enterResultsLink;
	}

	@Override
	public HasClickHandlers getLabValidateResultsLink() {
		return labValidateResultsLink;
	}

	@Override
	public HasClickHandlers getScientValidateResultsLink() {
		return scientValidateResultsLink;
	}

	@Override
	public HasClickHandlers getShowResultsLink() {
		return showResultsLink;
	}

}
